<!DOCTYPE html>
<html>
<head>
    <title>突发事件定位</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="format-detection" content="telephone=no" />
<meta charset="utf-8" />
 <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
    <link rel="stylesheet" href="../css/weui.css"/>
    <link rel="stylesheet" href="../css/example.css"/>
<style type="text/css">
    body, html,#allmap {width: 100%;height: 70%;margin:0;font-family:"微软雅黑";}
</style>
<script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=cR98TwX2FnKTpANIOYhMYMot9a4ioxjc"></script>
</head>
<body>
<div id="allmap" style="width: 100%;height: 100%;"></div>
<div class="weui-cells">
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">标题</label></div>
        <div class="weui-cell__bd">
            <input id="title" class="weui-input" type="text" value="" placeholder="输入标题"/>
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">报告人</label></div>
        <div class="weui-cell__bd">
            <input id="reportUser" class="weui-input" type="text" value="" placeholder="报告人"/>
        </div>
    </div>
</div>
<div class="weui-cells">
    <div class="weui-cells__title">报告内容</div>
    <div class="weui-cell">
        <div class="weui-cell__bd">
            <textarea id="reportContext" class="weui-textarea" placeholder="输入报告内容" rows="3"></textarea>
            <div class="weui-textarea-counter"><span>0</span>/200</div>
        </div>
    </div>
</div>
<div class="weui-cells">
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">位置</label></div>
        <div class="weui-cell__bd">
            <input id="place" class="weui-input"  value=""/>
        </div>
    </div>
</div>
<div class="weui-cells">
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">报告时间</label></div>
        <div class="weui-cell__bd">
            <input id="time" class="weui-input"  value=""/>
        </div>
    </div>
</div>


<a href="javascript:;" id="report" class="weui-btn weui-btn_plain-primary">确定</a>
<div class="weui-cell weui-cell_warn">
    <div class="weui-cell__hd"><span class="weui-cell__hd"><a class="btn btn_an3" href="tel:119">紧急呼叫</a></span></div>
    <div class="weui-cell__bd">
    </div>
    <div class="weui-cell__ft">
        <span class="weui-cell__ft"><a href="safeLike.html">安全通讯录</a></span>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
   }

 var lng=getQueryString("longitude");
 var lat=getQueryString("latitude");

   var map = new BMap.Map("allmap", {enableMapClick:true});//构造底图时，关闭底图可点功能
   var point = new BMap.Point(lng, lat);
      map.centerAndZoom(point, 13);
      var marker = new BMap.Marker(point); // 创建点
  	map.addOverlay(marker);    //增加点
  	var str = "我的位置";
  	var opts = {
  			   position : point,    // 指定文本标注所在的地理位置
  			   offset   : new BMap.Size(-getByteLen(str)*3, 5)    //设置文本偏移量
  			}	
  	var label = new BMap.Label(str, opts);  // 创建文本标注对象
  	label.setStyle({
  					 fontSize : "12px",
  					 height : "20px",
  					 lineHeight : "20px",
  					 fontFamily:"微软雅黑"
  				  });
      map.addOverlay(label);   
      
      map.enableScrollWheelZoom(true);
      var geoc = new BMap.Geocoder();  

      //获取标注位置信息    
      function getAttr(){
  		var p = marker.getPosition();       //获取marker的位置
  		alert("marker的位置是" + p.lng + "," + p.lat);   
  	}
   
      function getByteLen(val) {    //传入一个字符串
    	    var len = 0;
    	    for (var i = 0; i < val.length; i++) {
    	        if (val[i].match(/[^\x00-\xff]/ig) != null) //全角 
    	            len += 2; //如果是全角，占用两个字节  如果mysql中某字段是text, 如果设置编码为utf-8,那么一个中文是占3个字节, gbk是两个字节
    	        else
    	            len += 1; //半角占用一个字节
    	    }
    	    return len;
    	 }
      
      geoc.getLocation(point, function(rs){
			var addComp = rs.addressComponents;
			$("#place").val(addComp.city  + addComp.district  + addComp.street  + addComp.streetNumber);
		});
      
      
   // 获取当前日期
      var date = new Date();
      // 获取当前月份
      var nowMonth = date.getMonth() + 1;
      // 获取当前是几号
      var strDate = date.getDate();
      // 添加分隔符“-”
      var seperator = "-";
      // 对月份进行处理，1-9月在前面添加一个“0”
      if (nowMonth >= 1 && nowMonth <= 9) {
         nowMonth = "0" + nowMonth;
      }
      // 对月份进行处理，1-9号在前面添加一个“0”
      if (strDate >= 0 && strDate <= 9) {
         strDate = "0" + strDate;
      }
      // 最后拼接字符串，得到一个格式为(yyyy-MM-dd)的日期
      var nowDate = date.getFullYear() + "年" + nowMonth + "月" + strDate+"日";

      $("#time").val(nowDate);
      
      
      $.post('/shambles/mobile/register/userinfoByopenId.do', {
			campusId:1
	       },function(data){
	    	   var obj = $.parseJSON(data);
	    	   if(obj.name!=null)
	    	   $("#reportUser").val(obj.name);
	       });
      
      $("#report").click(function(){
    	  var title=$("#title").val();
    	  var reportUser=$("#reportUser").val();
    	  var reportContext=$("#reportContext").val();
    	  var place=$("#place").val();  		        
    	  
    	  var url=window.location.host+"/shambles/mobile/1/hidden/safePlace.html?lng="+lng+"&lat="+lat;
    	  
    	  $.get("/shambles/mobile/WechatSendMessage/send.do", { 
    		  title:title,
    		  reportUser:reportUser,
    		  reportContext:reportContext,
    		  place:place,
    		  url:url
    		  }, function(data) {
    			  alert(data);
    		  });
      })
      
      
</script>
